package com.spider.dao;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;

import com.spider.dao.filter.HBaseFilter;
import com.spider.dao.filter.HBaseFilterImp;

public class Test1 {
	
	HBaseDao dao = new HBaseDAOImp();
	HBaseFilter filter = new HBaseFilterImp();
	
//	@Test
//	public void tableFilter() {
//		filter.KeyOnlyFilter("Student");
//	}
	

	public void familyFilter() {
		List<Result> list = filter.ValueFilter("Student", "38256471");
		String rowKey = null;
		for (Result result : list) {
			for (KeyValue key : result.raw()) {
				rowKey = Bytes.toString(key.getRow());
			}
		}
		List<Result> userList = filter.RowFilter("Student", rowKey);
		for (Result result : list) {
			for (KeyValue key : result.raw()) {
				System.out.println("rowKey:"+ Bytes.toString(key.getRow()));
				System.out.println("qui:"+Bytes.toString(key.getQualifier()));
				System.out.println("value:"+Bytes.toString(key.getValue()));
			}
		}
	}
	
	public void queryByQualifierFilter(String tableName,String qualifier) {
		List<Result> list = filter.QualifierFilter(tableName, qualifier);
		for (Result result : list) {
			for (KeyValue key : result.raw()) {
				System.out.println("rowKey:"+Bytes.toString(key.getRow()));
				System.out.println("qualifier:"+Bytes.toString(key.getQualifier()));
				System.out.println("value:"+Bytes.toString(key.getValue()));
				System.out.println("------------------------------");
			}
		}
	}
	
	@Test
	public void queryByRowSubFilter() {
		List<Result> list = filter.RowSubFilter("Student", "");		
		for (Result result : list) {
			for (KeyValue key : result.raw()) {
				System.out.println("rowKey:"+Bytes.toString(key.getRow()));
				System.out.println("qualifier:"+Bytes.toString(key.getQualifier()));
				System.out.println("value:"+Bytes.toString(key.getValue()));
				System.out.println("------------------------------");
			}
		}
	}
	
	public static void main(String[] args) throws Exception {
		HBaseFilter filter = new HBaseFilterImp();
		List<Result> list= filter.FamilyFilter("Knowledge","base");
		for (Result result : list) {
			for (KeyValue key : result.raw()) {
				System.out.println(Bytes.toString(key.getQualifier()));
				System.out.println(Bytes.toString(key.getValue()));
			}
			System.out.println("----------------------");
		}
	}
}